﻿using Net5ApiANdWpfClient.Lib.Service;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace WpfClient.SystemManger
{
    /// <summary>
    /// PositioninfoAdd.xaml 的交互逻辑
    /// </summary>
    public partial class PositioninfoAdd : Window
    {
        public PositioninfoAdd()
        {
            InitializeComponent();
        }

        private void AddBtn_Click(object sender, RoutedEventArgs e)
        {
            Net5ApiANdWpfClient.Lib.Model.SystemAdmin.positioninfo infoAdd = new Net5ApiANdWpfClient.Lib.Model.SystemAdmin.positioninfo();//实例化类
            string po_name = un.Text;
            string po_other_name = unf.Text;
            if (string.IsNullOrEmpty(po_name))
            {
                MessageBox.Show("职位不能为空");
                return;
            }
            if (string.IsNullOrEmpty(po_other_name))
            {
                MessageBox.Show("别名不能为空");
                return;
            }
           
            infoAdd.po_name = po_name;
            infoAdd.po_other_name = po_other_name;
            infoAdd.po_createtime = DateTime.Now;
            positioninfoService service = new positioninfoService();
            string mess = "";
            bool result = service.positioninfodd(infoAdd, out mess);
            if(result)
            {
                MessageBox.Show($"添加成功,具体原因是:{mess}");
                //this.Close();
                MainWindow main = null;
                foreach (var w in Application.Current.Windows)
                {
                    if (w.GetType() == typeof(MainWindow))
                    {
                        main = w as MainWindow;
                    }

                }
                // MainWindow main = Application.Current.Windows

                //    FirstOrDefault(c=>c.).Cast<MainWindow>().;
                if (main != null)
                {
                    positioninfo paike = main.MainMdiWindow.Children.FirstOrDefault(c => c.Content.GetType() == typeof(positioninfo)).Content as positioninfo;
                    if (paike != null) paike.Search();
                }
                this.Close();

            }
            else
            {
                MessageBox.Show($"添加失败,具体原因是:{mess}");
            }


        }
    }
}
